-module(serverexample).
-export([start_server/0,handle_connection/1]).

start_server() ->
	case gen_tcp:listen(2099, [binary]) of
		{ok, ListenSocket} -> 
			accept(ListenSocket);
		{error, Reason} ->
			io:fwrite("Failure: ~w~n", [Reason])
	end.
	
accept(ListenSocket) ->
	{ok, Socket} = gen_tcp:accept(ListenSocket),
	spawn(server_example, handle_connection, [Socket]),
	accept(ListenSocket).
	
handle_connection(Socket) ->
	io:fwrite("Handling connection for Socket: ~w~n", [Socket]).